package com.ax.service.imple;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;

import com.ax.pojo.TabLable;
import com.ax.service.TabLableService;
import com.ax.utils.BaseDaoSupport;
import com.ax.utils.PageInfo;

@Service("tabLableService")
public class TabLableServiceImple implements TabLableService {
	private BaseDaoSupport<TabLable> dao;
	
	@Resource(name="sessionFactory")
	public void setSessionFactort(SessionFactory sessionFactory){
		 dao=new BaseDaoSupport<TabLable>();
		 dao.setSessionFactory(sessionFactory);
	}

	public boolean delTabLable(TabLable tabLable) {
		boolean flag=true;
		try {
			dao.delete(tabLable);
		} catch (Exception e) {
			flag=false;
		}
		return flag;
	}

	public PageInfo findPageInfo(int currentPageSize, String code) {
		PageInfo pageInfo=new PageInfo();
		pageInfo.setData(dao.getPaginationData(code+" order by po.lid desc", currentPageSize, pageInfo.getPageSize(), TabLable.class, null));
		pageInfo.setTotalCount(((Long)dao.getDataCount(TabLable.class, code)).intValue());
		pageInfo.setCurPage(currentPageSize);
		return pageInfo;
	}

	public TabLable getTabLable(String lName) {
		
		return (TabLable)dao.executeHQLForObject("from TabLable l where l.lname=?",new Object[]{lName});
	}

	public TabLable getTabLable(int lId) {
		// TODO Auto-generated method stub
		return (TabLable) dao.getHibernateTemplate().get(TabLable.class, lId);
	}

	public boolean saveTabLable(TabLable tabLable) {
		boolean flag=true;
		try {
			dao.save(tabLable);
		} catch (Exception e) {
			flag=false;
		}
		return flag;
	}

	public boolean updateTabLable(TabLable tabLable) {
		boolean flag=true;
		try {
			dao.update(tabLable);
		} catch (Exception e) {
			flag=false;
		}
		return flag;
	}
}
